#pragma once

#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
#include <functional>
#include <map>

// 定义一种函数类型,其返回值为void,没有参数
// using func = std::function<void()> ;
typedef std::function<void()> func;

std::vector<func> callBacks;
std::map<int, std::string> desc;

void readMySQL()
{
    std::cout << "sub process[" << getpid() << "] 执行访问数据的任务\n" << std::endl;
}

void execulUrl()
{
    std::cout << "sub process[" << getpid() << "] 执行URL解析\n" << std::endl;
}

void cal()
{
    std::cout << "sub process[" << getpid() << "] 执行加密任务\n" << std::endl;
}

void save()
{
    std::cout << "sub process[" << getpid() << "] 执行数据持久化任务\n" << std::endl;
}

// 加载任务
void load()
{
    desc[callBacks.size()] = "readMySQL: 读取数据库";
    callBacks.push_back(readMySQL);

    desc[callBacks.size()] = "execulUrl: 进行URL解析";
    callBacks.push_back(execulUrl);

    desc[callBacks.size()] = "cal: 进行加密计算";
    callBacks.push_back(cal);

    desc[callBacks.size()] = "save: 进行数据的文件保存";
    callBacks.push_back(save);
}

void showHandler()
{
    for(const auto& kv : desc)
    {
        std::cout << kv.first << "\t" << kv.second << std::endl;
    }
}

int handlerSize()
{
    return callBacks.size();
}
